package com.zp.self.module.eventBus.service;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.zp.self.module.eventBus.bean.MessageEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MessagePublisherServiceImpl {

    private final EventBus eventBus;
    private final AsyncEventBus asyncEventBus;

    @Autowired
    public MessagePublisherServiceImpl(final EventBus eventBus, AsyncEventBus asyncEventBus){
        this.eventBus = eventBus;
        this.asyncEventBus = asyncEventBus;
    }

    public void sendMessage(MessageEvent messageEvent){
        this.eventBus.post(messageEvent);
        log.info("send message...");
    }

    public void asyncSendMessage(MessageEvent messageEvent){
        this.asyncEventBus.post(messageEvent);
        log.info("send message...");
    }

}